﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using DAL.Entities;
using System.Data.SqlClient;

namespace DAL.EntitiesDAL
{
    public class DuocnangluongDAL : BaseDAL, UTL.IBaseDAL
    {
        #region Implement

        public int Count()
        {
            throw new NotImplementedException();
        }

        public DataTable Select()
        {
            return ExecuteQuery("sp_SelectAll_Duocnangluong");
        }

        public DataTable Select_Nhanvien()
        {
            return ExecuteQuery("sp_SelectAll_Nhanvien");
        }

        public DataTable Select_Nangluong()
        {
            return ExecuteQuery("sp_SelectAll_Nangluong");
        }

        public DataTable Select_Danhsach_Nangluong(string name)
        {
            var sql = "set dateformat dmy; execute sp_SelectAll_Danhsach_Nangluong " + name + " ";
            sql = string.Format(sql, name);
            return ExecuteQuery(sql);
        }

        public DataTable Select(object obj)
        {
            throw new NotImplementedException();
        }

        public object GetByKey(object key)
        {
            throw new NotImplementedException();
        }

        public bool Delete(string id)
        {
            var sql = "sp_Delete_Duocnangluong '{0}' ";
            sql = string.Format(sql, id);
            return ExecuteNonQuery(sql) > 0 ? true : false;
        }

        public bool Delete_Duocnangluong(string id, string id1)
        {
            var sql = "sp_Delete_Duocnangluong '{0}', '{1}' ";
            sql = string.Format(sql, id, id1);
            return ExecuteNonQuery(sql) > 0 ? true : false;
        }

        public bool Insert(object obj)
        {
            var o = (Duocnangluong)obj;
            var sql = "set dateformat dmy; execute sp_Insert_Duocnangluong '{0}', '{1}', '{2}' ";
            sql = string.Format(sql, o.STT_QDNL, o.MANHANVIEN, o.SOTIEN);
            return ExecuteNonQuery(sql) > 0 ? true : false;
        }

        public bool Update(object obj)
        {
            var o = (Duocnangluong)obj;
            var sql = "set dateformat dmy; execute sp_Update_Duocnangluong '{0}', '{1}', '{2}' ";
            sql = string.Format(sql, o.STT_QDNL, o.MANHANVIEN, o.SOTIEN);
            return ExecuteNonQuery(sql) > 0 ? true : false;
        }

        public DataTable Search(string name)
        {
            var sql = @"Select * from tb_Duocnangluong";
            sql = string.Format(sql, name);
            return ExecuteQuery(sql);
        }

        public DataTable Search(DAL.Entities.Duocnangluong o)
        {
            string sql;
            if (o.STT_QDNL != "")
                sql = @"Select * from tb_Duocnangluong Where STT_QDNL like '%" + o.STT_QDNL + "%' ";
            else
                sql = @"Select * from tb_Duocnangluong Where MANHANVIEN like N'%" + o.MANHANVIEN + "%' ";

            return ExecuteQuery(sql);
        }

        #endregion
    }
}
